import { instance } from "./api.interceptor"
import { CreateTestDTO, ICreateLesson, ILesson, IQuestion, ITest, IUpdateLesson } from "../interfaces"



export const TestService = {
    async getQuestions(testId: number): Promise<IQuestion[]> {
        const resp = await instance.get<IQuestion[]>(`/test/questions/${testId}`)
        return resp.data
    },

    async create(dto: CreateTestDTO): Promise<ITest> {
        const resp = await instance.post<any>(`/test/`, dto)
        return resp.data
    },

    async checkOneTest(data: {
        testId: number,
        answers: {
            question: string, answer: string
        }[]
    }):
        Promise<{
            correctAnswers: string[],
            wrongAnswers: string[],
            passed: boolean
        }> {
        const resp = await instance.post<any>(`/test/check-answers/${data.testId}`, data.answers)
        return resp.data
    },
    async checkManyTests(tests: {
        testId: number,
        answers: {
            question: string, answer: string
        }[]
    }[]):
        Promise<{
            correctAnswers: { testId: number; answers: string[] }[],
            wrongAnswers: { testId: number; answers: string[] }[],
            passed: boolean
        }> {
        const resp = await instance.post<any>(`/test/check-answers/`, tests)
        return resp.data
    }

}
